﻿/*-----------------------------------------------
// File: GuidePanel.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Battle.View
{
    public class GuidePanel : MonoBehaviour
    {
        public GameObject mask;
        public Transform guideTrans;
        public GameObject optionalTarget;
        public GameObject tip;
        public UILabel tipLabel;

        public GameObject arrow;

        List<GuideObjInfo> curGuideInfos = new List<GuideObjInfo>();

        public void OnGuidePanelClick()
        {
            var viewCtrl = BattleViewCtrl.GetInstance() as CGuideBattleViewCtrl;
            if (viewCtrl != null)
            {
                viewCtrl.OnGuidePanelClick();
            }
        }

        public void Show(GameObject obj, bool isUI, CGuideBattleViewCtrl.GuideStep step)
        {
            Hide();
            if (obj != null && isUI)
            {
                GuideObjInfo info = new GuideObjInfo();
                info.obj = obj;
                info.preTrans = obj.transform.parent;
                obj.transform.SetParent(guideTrans);
                obj.SetActive(false);
                obj.SetActive(true);
                curGuideInfos.Add(info);
            }
            switch (step)
            {
                case CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Cast:
                    // 让桐人放技能
                    // 提示桐人的battleheroItem
                    if (obj != null)
                    {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Right_Click, obj.transform.localPosition);
                    }
                    // 强制，有黑色遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 1f);
                    // 没有Tip
                    HideTip();
                    break;
                case CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pre:
                case CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pre:
                    // 显示释放技能
                    // 没有Focus
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，透明遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 0.01f);
                    // 没有Tip
                    HideTip();
                    break;
                case CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pause:
                    // 暂停，讲解浮空连击
                    // 没有Focus
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，黑色遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 1f);
                    // 有Tip：敌人当前属于浮空状态，对其进行连击，会掉出魔晶石，可增加团队能量。
                    ShowTip(TableTextBlo.GetText("combo_guide_text_001"), new Vector3(420, -128, 0));
                    break;
                case CGuideBattleViewCtrl.GuideStep.MainHero_Combo_FirstSkill_Cast:
                    // 让主角放技能
                    // Focus主角battleHeroItem
                    if (obj != null)
                    {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Right_Click, obj.transform.localPosition);
                    }
                    // 强制，黑色遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 1f);
                    // 有Tip：现在点击主角头像，进行连击
                    ShowTip(TableTextBlo.GetText("combo_guide_text_002"), new Vector3(0, -128, 0));
                    break;
                case CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Pre:
                case CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Pre:
                    // 连击前半段
                    // 没有Focus
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，透明遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 0.01f);
                    // 没有Tip
                    HideTip();
                    break;
                case CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Pause:
                    // 讲解掉落的魔晶石
                    // focus魔晶石
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，透明遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 0.01f);
                    // 有Tip: 箭头指示即为魔晶石，可增加团队能量
                    ShowTip(TableTextBlo.GetText("combo_guide_text_003"), new Vector3(480, -128, 0));

                    arrow.SetActive(true);
                    break;
                case CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Last:
                case CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Last:
                    // 结束第一次连击
                    // 没有focus
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，透明遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 0.01f);
                    // 没有Tip
                    HideTip();
                    break;
                case CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Cast:
                    // 桐人释放第二个技能
                    // focus桐人的battleheroitem
                    if (obj != null)
                    {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Right_Click, obj.transform.localPosition);
                    }
                    // 强制，黑色遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 1f);
                    // 没有Tip
                    HideTip();
                    break;
                case CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pause:
                    // 暂停，讲解倒地连击
                    // 没有Focus
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，黑色遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 1f);
                    // 有Tip：敌人当前处于倒地状态，对其进行连击，会掉出炎魔石，可增加角色伤害。
                    ShowTip(TableTextBlo.GetText("combo_guide_text_004"), new Vector3(420, -128, 0));
                    break;
                case CGuideBattleViewCtrl.GuideStep.Asuna_Combo_SecondSkill_Cast:
                    // 亚斯娜连击
                    // focus亚斯娜的battleheroitem
                    if (obj != null)
                    {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Right_Click, obj.transform.localPosition);
                    }
                    // 强制，黑色遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UIWidget>().color = new Color(1f, 1f, 1f, 1f);
                    // 有Tip：现在点击亚丝娜头像，进行连击。
                    ShowTip(TableTextBlo.GetText("combo_guide_text_005"), new Vector3(420, -128, 0));
                    break;
                case CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Pause:
                    // 连击暂停，讲解炎魔石
                    // focus 石头
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，透明遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UISprite>().color = new Color(1f, 1f, 1f, 0.01f);
                    // 有Tip：箭头所指即为炎魔石，可增加角色伤害
                    ShowTip(TableTextBlo.GetText("combo_guide_text_006"), new Vector3(480, -128, 0));
                    break;
                case CGuideBattleViewCtrl.GuideStep.GuideOver:
                    // 结束语
                    // 没有focus
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    // 强制，透明遮罩
                    mask.SetActive(true);
                    mask.GetComponent<UISprite>().color = new Color(1f, 1f, 1f, 0.01f);
                    // 有Tip：擅用连击可大大增加通关胜率，优质角色组合可以始终使敌人处于倒地状态或浮空状态。接下来的操作就靠自己完成吧！
                    ShowTip(TableTextBlo.GetText("combo_guide_text_007"), new Vector3(420, -128, 0));
                    break;
            }
        }

        public void Show(GameObject obj, BattleViewFirstCtrl.FirstBattleGuideStep step) {
            if (obj != null)
            {
                GuideObjInfo info = new GuideObjInfo();
                info.obj = obj;
                info.preTrans = obj.transform.parent;
                obj.transform.SetParent(guideTrans);
                obj.SetActive(false);
                obj.SetActive(true);
                curGuideInfos.Add(info);
            }
            switch (step) {
                case BattleViewFirstCtrl.FirstBattleGuideStep.Begin:
                    mask.GetComponent<UISprite>().color = new Color(0, 0, 0);
                    mask.SetActive(true);
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.NormalSkillNeedFirstCast:
                    mask.GetComponent<UISprite>().color = new Color(1, 1, 1);
                    if (obj != null)
                    {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Right_Click, obj.transform.localPosition);
                    }
                    ShowTip(TableTextBlo.GetText("battle_guide_01"), new Vector3(420,0,0));
                    mask.SetActive(true);
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.NormalSkillFirstCasting:
                    mask.SetActive(true);
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    HideTip();
                    mask.GetComponent<UISprite>().color = new Color(1, 1, 1, 0.01f);
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.NormalSkillNeedSecondCast:
                    mask.GetComponent<UISprite>().color = new Color(1, 1, 1);
                    if (obj != null)
                    {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Right_Click, obj.transform.localPosition);
                    }
                    ShowTip(TableTextBlo.GetText("battle_guide_02"), new Vector3(420,0,0));
                    mask.SetActive(true);
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.NormalSkillSecondCasting:
                    mask.GetComponent<UISprite>().color = new Color(1, 1, 1, 0.01f);
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    HideTip();
                    mask.SetActive(true);
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.NormalSkillNeedAllCast:
                    mask.SetActive(false);
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    if (obj != null) {
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.Left_Click, obj.transform.localPosition);
                    }
                    ShowTip(TableTextBlo.GetText("battle_guide_03"), new Vector3(420,0,0));
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.NormalSkillAllCasting:
                    mask.SetActive(false);
                    optionalTarget.GetComponent<GuideOptionTarget>().Hide();
                    HideTip();
                    break;
                case BattleViewFirstCtrl.FirstBattleGuideStep.UltimateSkillNeedFirstCast:
                    mask.GetComponent<UISprite>().color = new Color(1, 1, 1);
                    mask.SetActive(true);
                    ShowTip(TableTextBlo.GetText("battle_guide_04"), new Vector3(420, 0, 0));
                    if (obj != null && obj.GetComponent<BattleHeroItem>() != null) {
                        var item = obj.GetComponent<BattleHeroItem>();
                        item.ShowUltimateHelpTip();
                        optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.TopForwardDrag, obj.transform.localPosition + new Vector3(-25,0,0));
                    }
                    break;
            }
        }

        public void ShowUltimateHelp(BattleHeroItem item) {
            item.ShowUltimateHelpTip();
            var trans = item.transform.parent;
            item.transform.SetParent(guideTrans);
            optionalTarget.GetComponent<GuideOptionTarget>().Show(GuideOptionTarget.OptionalTargetType.TopForwardDrag, item.transform.localPosition);
            item.transform.SetParent(trans);
        }

        void ShowTip(string text, Vector3 pos) {
            tip.transform.localPosition = pos;
            tip.SetActive(true);
            tipLabel.text = text;
        }
        void HideTip() {
            tip.SetActive(false);
        }

        public void Hide() {
            foreach (var info in curGuideInfos) {
                info.obj.transform.SetParent(info.preTrans);
                info.obj.SetActive(false);
                info.obj.SetActive(true);
            }
            curGuideInfos.Clear();
            mask.SetActive(false);
            optionalTarget.GetComponent<GuideOptionTarget>().Hide();
            HideTip();
            arrow.SetActive(false);
        }
    }

    public class GuideObjInfo {
        public GameObject obj;
        public Transform preTrans;
    }
}